package com.instwall.callbase.thread;


import java.util.LinkedList;


public class WorkQueue {
    private LinkedList<ITask> mQueue;
    private ITask currentTask = null;

    public WorkQueue() {
        mQueue = new LinkedList<>();
    }

    public synchronized void addQueue(ITask task) {
        if (task != null) {
            mQueue.add(task);
        }
    }

    public synchronized ITask getTask() {
        try {
            currentTask = mQueue.removeFirst();
        } catch (Exception e) {
            return null;
        }
        return currentTask;
    }

    public synchronized void remove(ITask task) {
        if (task != null) {
            mQueue.remove(task);
        }
    }

    public synchronized void removeAll() {
        mQueue.clear();
    }


    public synchronized ITask getCurrentTask() {
        return currentTask;
    }
}
